<script>
	export default {
		onLaunch: function() {
			console.log('App Launch')
			var ua = window.navigator.userAgent.toLowerCase();
			if (ua.match(/MicroMessenger/i) == 'micromessenger') {
				// uni.navigateTo({
				// 	url:'/pages/go/go'
				// })
				// 微信中打开
			} else {
				// 普通浏览器中打开
			}
			this.$wqzApi.Index_floor_style({}).then(res => {
				uni.setStorageSync('style', res.data.data)
			})
			this.getMessage()
			setInterval(() => {
				this.getMessage()
			}, 6000)
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			getMessage() {
				var token = uni.getStorageSync('token')
				if (token) {
					this.$wqzApi.message_read({}).then(res => {
						var id = res.data.order_id
						if (res.data.id) {
							var that = this
							uni.setStorageSync('messageInfo', res.data)
							uni.showModal({
								title: '提示',
								content: '您有新的留言',
								cancelText: '确定',
								confirmText: '查看留言',
								success: function(res) {
									if (res.confirm) {
										uni.navigateTo({
											url: `/pages/goods_order_info/goods_order_info?order_id=${id}`
										})
									} else if (res.cancel) {
										that.messageUpdate(id)
									}
								}
							});
						} else {
							uni.setStorageSync('messageInfo', null)
						}
					})
				}
			},
			// 已读消息
			messageUpdate(id) {
				this.$wqzApi.message_update({
					order_id: id
				}).then(res => {

				})
			}
		}
	}
</script>


<style lang="scss">
	/*每个页面公共css */
	@import "uview-ui/index.scss";
	@import url('@/common/_style.scss');

	.xqTVQ {
		width: 50rpx !important;
		height: 50rpx !important;
	}
</style>